<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Stores a file in the database</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongogridfs.get.html">« MongoGridFS::get</a></li>
      <li style="float: right;"><a href="mongogridfs.remove.html">MongoGridFS::remove »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongogridfs.html">MongoGridFS</a></li>
    <li>Stores a file in the database</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongogridfs.put" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoGridFS::put</h1>
  <p class="verinfo">(PECL mongo &gt;=1.0.8)</p><p class="refpurpose"><span class="refname">MongoGridFS::put</span> &mdash; <span class="dc-title">Stores a file in the database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongogridfs.put-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>MongoGridFS::put</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$metadata</code><span class="initializer"> = array()</span></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = array()</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>


  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="methodname"><strong>MongoGridFS::put()</strong></span> is an alias of <span class="methodname"><a href="mongogridfs.storefile.html" class="methodname">MongoGridFS::storeFile()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongogridfs.put-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>

      <code class="parameter">filename</code>
     </dt>

     <dd>

      <p class="para">
       Name of the file to store.
      </p>
     </dd>

    
    
     <dt>

      <code class="parameter">metadata</code>
     </dt>

     <dd>

      <p class="para">
       Other metadata fields to include in the file document.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">These fields may also overwrite those that would be created automatically by the driver, as described in the MongoDB core documentation for the <a href="https://docs.mongodb.com/manual/core/gridfs/#the-files-collection" class="link external">&raquo;&nbsp;files collection</a>. Some practical use cases for this behavior would be to specify a custom <code class="literal">chunkSize</code> or <code class="literal">_id</code> for the file.</p></p></blockquote>
     </dd>

    
    
     <dt>

      <code class="parameter">options</code>
     </dt>

     <dd>

      <p class="para">
       An array of options for the insert operations executed against the
       <code class="literal">chunks</code> and <code class="literal">files</code> collections. See
       <span class="function"><a href="mongocollection.insert.html" class="function">MongoCollection::insert()</a></span> for documentation on these
       these options.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongogridfs.put-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">Returns the <code class="literal">_id</code> of the saved file document. This will be a generated <a href="class.mongoid.html" class="classname">MongoId</a> unless an <code class="literal">_id</code> was explicitly specified in the <code class="parameter">metadata</code> parameter.</p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongogridfs.put-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws <a href="class.mongogridfsexception.html" class="classname">MongoGridFSException</a> if there is an error
   reading <code class="parameter">filename</code> or inserting into the
   <code class="literal">chunks</code> or <code class="literal">files</code> collections.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongogridfs.put-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="mongogridfs.storebytes.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeBytes()</a> - Stores a string of bytes in the database</span></li>
   <li class="member"><span class="function"><a href="mongogridfs.storefile.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeFile()</a> - Stores a file in the database</span></li>
   <li class="member"><span class="function"><a href="mongogridfs.storeupload.html" class="function" rel="rdfs-seeAlso">MongoGridFS::storeUpload()</a> - Stores an uploaded file in the database</span></li>
   <li class="member">MongoDB core docs on <a href="https://docs.mongodb.com/manual/core/gridfs/" class="link external">&raquo;&nbsp;GridFS</a></li>
  </ul>
 </div>


</div></div></div></body></html>